use axum::Json;
use chrono::{NaiveDate, NaiveTime, NaiveDateTime};
use serde_json::{Number, Value};
use sea_orm::prelude::{DateTimeUtc, Decimal, Json as SqlJson};

use crate::code;
pub mod valid;
pub mod utils;
/* ——————————————————————————— 模块 ——————————————————————————— */
// pub mod dec;
pub mod vec_num_to_vec_str;
/* —————————————————————————————————————————————————————————————————— 解析 json Value —————————————————————————————————————————————————————————————————— */
/* ——————————————————————————— 必填项 ——————————————————————————— */
pub fn str(json:&Value, field:&str) -> Result<String, Json<Value>> {
    if let Some(f) = str_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn blob(json:&Value, field:&str) -> Result<Vec<u8>, Json<Value>> {
    if let Some(f) = blob_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn i64(json:&Value, field:&str) -> Result<i64, Json<Value>> { // 整数
    if let Some(f) = i64_op(json, field)?{
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn f64(json:&Value, field:&str) -> Result<f64, Json<Value>> {	// 小数
    if let Some(f) = f64_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn f32(json:&Value, field:&str) -> Result<f32, Json<Value>>  { Ok( f64(json, field)? as f32 ) }
pub fn i8(json:&Value, field:&str) -> Result<i8, Json<Value>>  { Ok( i64(json, field)? as i8 ) }
pub fn i16(json:&Value, field:&str) -> Result<i16, Json<Value>> { Ok( i64(json, field)? as i16 ) }
pub fn i32(json:&Value, field:&str) -> Result<i32, Json<Value>> { Ok( i64(json, field)? as i32 ) }
pub fn u32(json:&Value, field:&str) -> Result<u32, Json<Value>> { Ok( i64(json, field)? as u32 ) }
pub fn u8(json:&Value, field:&str) -> Result<u8, Json<Value>> { Ok( i64(json, field)? as u8 ) }
pub fn u16(json:&Value, field:&str) -> Result<u16, Json<Value>> { Ok( i64(json, field)? as u16 ) }
pub fn u64(json:&Value, field:&str) -> Result<u64, Json<Value>> { Ok( i64(json, field)? as u64 ) }
pub fn isize(json:&Value, field:&str) -> Result<isize, Json<Value>> { Ok( i64(json, field)? as isize ) }
pub fn usize(json:&Value, field:&str) -> Result<usize, Json<Value>> { Ok( i64(json, field)? as usize ) }
pub fn num(json:&Value, field:&str) -> Result<Number, Json<Value>> { 
    if let Some(f) = num_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn dec(json:&Value, field:&str) -> Result<Decimal, Json<Value>> { 
    if let Some(f) = dec_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}

pub fn bool(json:&Value, field:&str) -> Result<bool, Json<Value>> {
    match bool_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn date_time(json:&Value, field:&str) -> Result<NaiveDateTime, Json<Value>> {
    if let Some(f) = date_time_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn date_ymd_hm(json:&Value, field:&str) -> Result<NaiveDateTime, Json<Value>> {
    if let Some(f) = date_ymd_hm_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn date(json:&Value, field:&str) -> Result<NaiveDate, Json<Value>> {
    if let Some(f) = date_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn time(json:&Value, field:&str) -> Result<NaiveTime, Json<Value>> {
    if let Some(f) = time_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn date_time_utc(json:&Value, field:&str) -> Result<DateTimeUtc, Json<Value>> {
    if let Some(f) = date_time_utc_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn date_utc(json:&Value, field:&str) -> Result<DateTimeUtc, Json<Value>> {
    if let Some(f) = date_utc_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn time_hm(json:&Value, field:&str) -> Result<NaiveTime, Json<Value>> {
    if let Some(f) = time_hm_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn uuid(json:&Value, field:&str) -> Result<Vec<u8>, Json<Value>> {
    if let Some(f) = uuid_op(json, field)? {
        Ok(f)
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}

pub fn json(json:&Value, field:&str) -> Result<SqlJson, Json<Value>> {
    match json_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn json_arr(json:&Value, field:&str) -> Result<SqlJson, Json<Value>> {
    match json_arr_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn json_obj(json:&Value, field:&str) -> Result<SqlJson, Json<Value>> {
    match json_obj_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}

pub fn vec(json:&Value, field:&str) -> Result<Vec<Value>, Json<Value>> {
    match vec_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn vec_i64(json:&Value, field:&str) -> Result<Vec<i64>, Json<Value>> {
    match vec_i64_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn vec_i32(json:&Value, field:&str) -> Result<Vec<i32>, Json<Value>> {
    match vec_i32_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn vec_u32(json:&Value, field:&str) -> Result<Vec<u32>, Json<Value>> {
    match vec_u32_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn vec_str(json:&Value, field:&str) -> Result<Vec<String>, Json<Value>> {
    match vec_str_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn vec_str_vec_num(json:&Value, field:&str) -> Result<Vec<String>, Json<Value>> {
    match vec_str_vec_num_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn vec_i64_json(json:&Value, field:&str) -> Result<Vec<i64>, Json<Value>> {
    match vec_i64_json_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn vec_i32_json(json:&Value, field:&str) -> Result<Vec<i32>, Json<Value>> {
    match vec_i32_json_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn vec_u32_json(json:&Value, field:&str) -> Result<Vec<u32>, Json<Value>> {
    match vec_u32_json_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
pub fn vec_str_json(json:&Value, field:&str) -> Result<Vec<String>, Json<Value>> {
    match vec_str_json_op(json, field)? {
        Some( f ) => Ok(f),
        None =>  Err(code::err_code_msg_(501,field.to_string() + " 字段必填"))
    }
}
/* ——————————————————————————— 可选项 ——————————————————————————— */
pub fn str_op(json:&Value, field:&str) -> Result<Option<String>, Json<Value>> { 
    let value = &json[field];
    if value.is_null(){
        Ok( None )
    }else{
        match value.as_str() {
			Some(f) => Ok( Some(f.to_string()) ),
			None => {
				if value.is_i64(){
					Ok( value.as_i64().and_then(|f| Some(f.to_string()) ) )
				}else if value.is_f64(){
					Ok( value.as_f64().and_then(|f| Some(f.to_string()) ) )
				}else if value.is_boolean(){
					Ok( value.as_bool().and_then(|f| Some(f.to_string()) ) )
				}else if value.is_array(){
                    let mut arr: Vec<String> = Vec::new();
                    if let Some( k ) = value.as_array() {
                        for v in k {
                            if v.is_string() || v.is_i64() {
                                arr.push(v.to_string())
                            }
                        }
                        Ok( Some( arr.join(",") ) )
                    }else{
                        Ok(None)
                    }
				}else{
					Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是字符串"))
				}
			}
		}
    }
}
pub fn str_op_(json:&Value, field:&str) -> Result<Option<String>, Json<Value>> {
    let value = &json[field];
    if value.is_null() {
        Ok( None )
    }else{
        match value.as_str() {
            Some( f) => Ok(Some( f.to_owned() )),
            None => Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是整数"))
        }
    }
}
pub fn blob_op(json:&Value, field:&str) -> Result<Option<Vec<u8>>, Json<Value>> {
    let value = &json[field];
    if value.is_null() {
        Ok( None )
    }else{
        match value.as_str() {
            Some( f) => Ok(Some( f.as_bytes().to_vec() )),
            None => Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是字符串"))
        }
    }
}
pub fn i64_op(json:&Value, field:&str) -> Result<Option<i64>, Json<Value>> {
    let value = &json[field];
    if value.is_null() {
        Ok( None )
    }else{
        match value.as_i64() {
            Some( f) => Ok(Some( f )),
            None => {
				if value.is_string() {
				    match value.as_str() {
				        Some(f) => {
				            match f.parse::<i64>() {
				                Ok(v) => Ok(Some(v)),
				                Err(_e) => Err(code::err_code_msg_(501,field.to_string() + " 字段必须是整数"))
				            }
				        },
				        None => Ok(None)
				    }
				} else if value.is_boolean() {
                    let v = if value.as_bool().unwrap_or_default() { 1 } else { 0 };
                    Ok(Some(v))
                }else{
					Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是整数"))
				}
			}
        }
    }
}
pub fn i64_op_(json:&Value, field:&str) -> Result<Option<i64>, Json<Value>> {
    let value = &json[field];
    if value.is_null() {
        Ok( None )
    }else{
        match value.as_i64() {
            Some( f) => Ok(Some( f )),
            None => Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是整数"))
        }
    }
}
pub fn i32_op_(json:&Value, field:&str) -> Result<Option<i32>, Json<Value>> {
    let value = &json[field];
    if value.is_null() {
        Ok( None )
    }else{
        match value.as_i64() {
            Some( f) => Ok(Some( f as i32 )),
            None => Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是整数"))
        }
    }
}

pub fn num_op(json:&Value, field:&str) -> Result<Option<Number>, Json<Value>> {
    let value = &json[field];
    if value.is_null() {
        Ok( None )
    }else{
        match value.as_number() {
            Some( f) => Ok(Some( f.to_owned() )),
            None => {
				if value.is_string() {
				    match value.as_str() {
				        Some(f) => {
				            match f.parse::<Number>() {
				                Ok(v) => Ok(Some(v)),
				                Err(_e) => Err(code::err_code_msg_(501,field.to_string() + " 字段必须是整数"))
				            }
				        },
				        None => Ok(None)
				    }
				} else if value.is_boolean() {
                    let v = if value.as_bool().unwrap_or_default() { 1 } else { 0 };
                    Ok(Some(Number::from(v)))
                }else{
					Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是整数"))
				}
			}
        }
    }
}
pub fn dec_op(json:&Value, field:&str) -> Result<Option<Decimal>, Json<Value>> {
    let value = &json[field];
    if value.is_null() {
        Ok( None )
    }else if value.is_f64() {
        match value.as_f64() {
            Some( f) => {
                match Decimal::from_str_exact(&f.to_string()) {
                    Ok(v) => Ok(Some(v)),
                    Err(_e) => Err(code::err_code_msg_(501,field.to_string() + " 字段必须是数字"))
                }
            },
            None => Ok(None)
        }
    }else if value.is_i64(){
        match value.as_i64() {
            Some( f) => {
                Ok(Some( Decimal::from(f) ))
            },
            None => Ok(None)
        }
    }else if value.is_string(){
        match value.as_str() {
            Some(f) => {
                
                match Decimal::from_str_exact(f) {
                    Ok(v) => Ok(Some(v)),
                    Err(_e) => Err(code::err_code_msg_(501,field.to_string() + " 字段必须是数字"))
                }
            },
            None => Ok(None)
        }
    }else{
        Err(code::err_code_msg_(501,field.to_string() + " 字段必须是数字"))
    }
}
pub fn f64_op(json:&Value, field:&str) -> Result<Option<f64>, Json<Value>> {
    let value = &json[field];
    if value.is_null() {
        Ok( None )
    }else{
        match value.as_f64() {
            Some( f) => Ok(Some( f )),
            None => {
    			if value.is_string() {
    			    match value.as_str() {
    			        Some(f) => {
    			            match f.parse::<f64>() {
    			                Ok(v) => Ok(Some(v)),
    			                Err(_e) => Err(code::err_code_msg_(501,field.to_string() + " 字段必须是小数"))
    			            }
    			        },
    			        None => Ok(None)
    			    }
    				
    			}else{
    				Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是小数"))
    			}
    		}
        }
    }
}
pub fn f32_op(json:&Value, field:&str) -> Result<Option<f32>, Json<Value>> { Ok( f64_op(json, field)?.and_then(|v| Some( v as f32 )) ) }
pub fn i8_op(json:&Value, field:&str) -> Result<Option<i8>, Json<Value>> { Ok( i64_op(json, field)?.and_then(|v| Some( v as i8 ) )) }
pub fn i16_op(json:&Value, field:&str) -> Result<Option<i16>, Json<Value>> { Ok( i64_op(json, field)?.and_then(|v| Some( v as i16 )) ) }
pub fn i32_op(json:&Value, field:&str) -> Result<Option<i32>, Json<Value>> { Ok( i64_op(json, field)?.and_then(|v| Some( v as i32 )) ) }
pub fn u32_op(json:&Value, field:&str) -> Result<Option<u32>, Json<Value>> { Ok( i64_op(json, field)?.and_then(|v| Some( v as u32 )) ) }
pub fn u8_op(json:&Value, field:&str) -> Result<Option<u8>, Json<Value>> { Ok( i64_op(json, field)?.and_then(|v| Some( v as u8 ) )) }
pub fn u16_op(json:&Value, field:&str) -> Result<Option<u16>, Json<Value>> { Ok( i64_op(json, field)?.and_then(|v| Some( v as u16 ) )) }
pub fn u64_op(json:&Value, field:&str) -> Result<Option<u64>, Json<Value>> { Ok( i64_op(json, field)?.and_then(|v| Some( v as u64 ) )) }
pub fn isize_op(json:&Value, field:&str) -> Result<Option<isize>, Json<Value>> { Ok( i64_op(json, field)?.and_then(|v| Some( v as isize ) )) }
pub fn usize_op(json:&Value, field:&str) -> Result<Option<usize>, Json<Value>> { Ok( i64_op(json, field)?.and_then(|v| Some( v as usize ) )) }
pub fn bool_op(json:&Value, field:&str) -> Result<Option<bool>, Json<Value>> {
    let value = &json[field];
    if value.is_null() {
       Ok(None)
    }else{
		match value.as_bool() {
			Some(f) => Ok( Some(f) ),
			None => {
				if value.is_i64( ) {
					Ok( value.as_i64().and_then(|f| Some( f !=0 )))
				} else if value.is_string() {
					match value.as_str() {
						Some(f) => {
							if f == "true" || f == "1" {
								Ok(Some(true))
							}else if f == "false" || f == "0" {
								Ok( Some(false) )
							}else{
								Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是布尔值"))
							}
						},
						None => Ok(None)
					}
				}else {
					Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是布尔值"))
				}
			}
		}
    }
}
pub fn date_time_op(json:&Value, field:&str) -> Result<Option<NaiveDateTime>, Json<Value>> { 
    let value = &json[field];
    if value.is_null(){
        Ok( None )
    }else{
        if let Some(f) = value.as_str() {
            match super::chrono::date_time(&f) {
                Ok(f) => Ok( Some(f) ),
                Err(e) => Err( code::err_code_msg_(501,field.to_owned() + " " + e["msg"].as_str().unwrap_or_default()) )
            }
        }else{
            Err(code::err_code_msg_(501,field.to_string() + " 字段必须是日期字符串 yy-mm-dd hh:mm:ss"))
        }
    }
}
pub fn date_ymd_hm_op(json:&Value, field:&str) -> Result<Option<NaiveDateTime>, Json<Value>> { 
    let value = &json[field];
    if value.is_null(){
        Ok( None )
    }else{
        if let Some(f) = value.as_str() {
            match super::chrono::date_ymd_hm(&f) {
                Ok(f) => Ok( Some(f) ),
                Err(e) => Err( code::err_code_msg_(501,field.to_owned() + " " + e["msg"].as_str().unwrap_or_default()) )
            }
        }else{
            Err(code::err_code_msg_(501,field.to_string() + " 字段必须是日期字符串 yy-mm-dd hh:mm"))
        }
    }
}
pub fn date_op(json:&Value, field:&str) -> Result<Option<NaiveDate>, Json<Value>> { 
    let value = &json[field];
    if value.is_null(){
        Ok( None )
    }else{
        if let Some(f) = value.as_str() {
            match super::chrono::date(f) {
                Ok(f) => Ok( Some(f) ),
                Err(e) => Err( code::err_code_msg_(501,field.to_owned() + " " + e["msg"].as_str().unwrap_or_default()) )
            }
        }else{
            Err(code::err_code_msg_(501,field.to_string() + " 字段必须是日期字符串 yy-mm-dd"))
        }
    }
}
pub fn date_time_utc_op(json:&Value, field:&str) -> Result<Option<DateTimeUtc>, Json<Value>> { 
    let value = &json[field];
    if value.is_null(){
        Ok( None )
    }else{
        if let Some(f) = value.as_str() {
            match super::chrono::date_time_utc(f) {
                Ok(f) => Ok( Some(f) ),
                Err(e) => Err( code::err_code_msg_(501,field.to_owned() + " " + e["msg"].as_str().unwrap_or_default()) )
            }
        }else{
            Err(code::err_code_msg_(501,field.to_string() + " 字段必须是日期字符串 yy-mm-dd hh:mm:ss"))
        }
    }
}
pub fn date_utc_op(json:&Value, field:&str) -> Result<Option<DateTimeUtc>, Json<Value>> { 
    let value = &json[field];
    if value.is_null(){
        Ok( None )
    }else{
        if let Some(f) = value.as_str() {
            match super::chrono::date_utc(f) {
                Ok(f) => Ok( Some(f) ),
                Err(e) => Err( code::err_code_msg_(501,field.to_owned() + " " + e["msg"].as_str().unwrap_or_default()) )
            }
        }else{
            Err(code::err_code_msg_(501,field.to_string() + " 字段必须是日期字符串 yy-mm-dd"))
        }
    }
}
pub fn time_op(json:&Value, field:&str) -> Result<Option<NaiveTime>, Json<Value>> { 
    let value = &json[field];
    if value.is_null(){
        Ok( None )
    }else{
        if let Some(f) = value.as_str() {
            match super::chrono::time(f) {
                Ok(f) => Ok( Some(f) ),
                Err(e) => Err( code::err_code_msg_(501,field.to_owned() + " " + e["msg"].as_str().unwrap_or_default()) )
            }
        }else{
            Err(code::err_code_msg_(501,field.to_string() + " 字段必须是时间字符串 hh:mm:ss"))
        }
    }
}
pub fn time_hm_op(json:&Value, field:&str) -> Result<Option<NaiveTime>, Json<Value>> { 
    let value = &json[field];
    if value.is_null(){
        Ok( None )
    }else{
        if let Some(f) = value.as_str() {
            match super::chrono::time_hm(f) {
                Ok(f) => Ok( Some(f) ),
                Err(e) => Err( code::err_code_msg_(501,field.to_owned() + " " + e["msg"].as_str().unwrap_or_default()) )
            }
        }else{
            Err(code::err_code_msg_(501,field.to_string() + " 字段必须是时间字符串 hh:mm"))
        }
    }
}
pub fn uuid_op(json:&Value, field:&str) -> Result<Option<Vec<u8>>, Json<Value>> { 
    let value = &json[field];
    if value.is_null(){
        Ok( None )
    }else{
        match value.as_str() {
			Some(f) => Ok( Some(f.bytes().collect()) ),
			None => {
				Err(code::err_code_msg_(501,field.to_owned() + " 字段必须是字符串"))
			}
		}
    }
}

pub fn json_op(json:&Value, field:&str) -> Result<Option<SqlJson>, Json<Value>> { utils::json_op(&json[field], field) }
pub fn json_arr_op(json:&Value, field:&str) -> Result<Option<SqlJson>, Json<Value>> { utils::json_arr_op(&json[field], field) }
pub fn json_obj_op(json:&Value, field:&str) -> Result<Option<SqlJson>, Json<Value>> { utils::json_obj_op(&json[field], field) }
// 自动转换 josn 字符串 或 json数组
pub fn vec_op(json:&Value, field:&str) -> Result<Option<Vec<Value>>, Json<Value>> { utils::vec_op(&json[field], field)}
pub fn vec_i64_op(json:&Value, field:&str) -> Result<Option<Vec<i64>>, Json<Value>> {
    let value = &json[field];
    if value.is_null() { Ok(None) }
    else if value.is_string() {
        utils::vec_i64_str_op(&json[field], field)
    }else if value.is_array() {
        utils::vec_i64_json_op(&json[field], field)
    }else {
        Err(code::err_code_msg_(501,field.to_string() + " 字段必须是以 , 分隔的字符串，或一维数字数组"))
    }
}
pub fn vec_i32_op(json:&Value, field:&str) -> Result<Option<Vec<i32>>, Json<Value>> {
    let value = &json[field];
    if value.is_null() { Ok(None) }
    else if value.is_string() {
        utils::vec_i32_str_op(&json[field], field)
    }else if value.is_array() {
        utils::vec_i32_json_op(&json[field], field)
    }else {
        Err(code::err_code_msg_(501,field.to_string() + " 字段必须是以 , 分隔的字符串，或一维数字数组"))
    }
}
pub fn vec_u32_op(json:&Value, field:&str) -> Result<Option<Vec<u32>>, Json<Value>> {
    let value = &json[field];
    if value.is_null() { Ok(None) }
    else if value.is_string() {
        utils::vec_u32_str_op(&json[field], field)
    }else if value.is_array() {
        utils::vec_u32_json_op(&json[field], field)
    }else {
        Err(code::err_code_msg_(501,field.to_string() + " 字段必须是以 , 分隔的字符串，或一维数字数组"))
    }
}
pub fn vec_str_op(json:&Value, field:&str) -> Result<Option<Vec<String>>, Json<Value>> {
    let value = &json[field];
    if value.is_null() { Ok(None) }
    else if value.is_string() {
        utils::vec_str_str_op(&json[field], field)
    }else if value.is_array() {
        utils::vec_str_json_op(&json[field], field)
    }else {
        Err(code::err_code_msg_(501,field.to_string() + " 字段必须是以 , 分隔的字符串，或一维字符串数组"))
    }
}
pub fn vec_str_vec_num_op(json:&Value, field:&str) -> Result<Option<Vec<String>>, Json<Value>> { utils::vec_str_vec_num_op(&json[field], field) }
pub fn vec_i64_json_op(json:&Value, field:&str) -> Result<Option<Vec<i64>>, Json<Value>> { utils::vec_i64_json_op(&json[field], field) }
pub fn vec_i32_json_op(json:&Value, field:&str) -> Result<Option<Vec<i32>>, Json<Value>> { utils::vec_i32_json_op(&json[field], field) }
pub fn vec_u32_json_op(json:&Value, field:&str) -> Result<Option<Vec<u32>>, Json<Value>> { utils::vec_u32_json_op(&json[field], field) }
pub fn vec_str_json_op(json:&Value, field:&str) -> Result<Option<Vec<String>>, Json<Value>> { utils::vec_str_json_op(&json[field], field) }
